import * as allIcons from '@ant-design/icons';
import { MenuDataItem } from '@ant-design/pro-layout';
import React from 'react';

// FIX从接口获取菜单时icon为string类型
const MenuItemIcon = (menus: MenuDataItem[]): MenuDataItem[] => {
  menus.forEach((item) => {
    const { icon, children } = item;
    if (icon && typeof icon === 'string' && icon !== '') {
      item.icon = React.createElement(allIcons[icon]);
    }
    if (children && children.length > 0) {
      item.children = MenuItemIcon(children);
    }
  });
  console.log(menus);
  return menus;
};

export default MenuItemIcon;
